<?php

class Application_Model_Pilote
{
	protected $_pilNum;
	protected $_pays;
	protected $_pilNom;
	protected $_pilPrenom;
	protected $_pilDateNais;
	protected $_pilPigiste;
	protected $_pilPoints;
	protected $_pilPoids;
	protected $_pilTaille;
	protected $_pilTexte;
	protected $_ecurie;
	protected $_photos;
	protected $_sponsors;

	public function __construct(array $options = null)
	{
		if(is_array($options))
		{
			$this->setOptions($options);
		}
	}
	
	public function __set($name, $value)
	{
		$method = 'set' . $name;
		if(('mapper' == $name) || !method_exists($this, $method))
		{
			throw new Exception('Invalid pilote property');
		}
		$this->$method($value);
	}
	public function __get($name)
	{
		$method = 'get' . $name;
		if(('mapper' == $name) || !method_exists($this, $method))
		{
			throw new Exception('Invalid pilote property');
		}
		return $this->$method();
	}

	public function setOptions(array $options)
	{
		$methods = get_class_methods($this);
		foreach ($options as $key => $value)
		{
			$method = 'set' . ucfirst($key);
			if(in_array($method, $methods))
			{
				$this->$method($value);
			}
		}
		return $this;
    }
	
	public function setPilNum($pilNum)
	{
		$this->_pilNum = (int)$pilNum;
		return $this;
	}
	public function getPilNum()
	{
		return $this->_pilNum;
	}

	public function setPays(Application_Model_Pays $pays)
	{
		$this->_pays = $pays;
		return $this;
	}
	public function getPays()
	{
		return $this->_pays;
	}

	public function setPilNom($pilNom)
	{
		$this->_pilNom = (string)$pilNom;
		return $this;
	}
	public function getPilNom()
	{
		return $this->_pilNom;
	}

	public function setPilPrenom($pilPrenom)
	{
		$this->_pilPrenom = (string)$pilPrenom;
		return $this;
	}
	public function getPilPrenom()
	{
		return $this->_pilPrenom;
	}

	public function setPilDateNais($pilDateNais)
	{
		$this->_pilDateNais = (string)$pilDateNais;
		return $this;
	}
	public function getPilDateNais()
	{
		return $this->_pilDateNais;
	}

	public function setPilPigiste($pilPigiste)
	{
		$this->_pilPigiste = (int)$pilPigiste;
		return $this;
	}
	public function getPilPigiste()
	{
		return $this->_pilPigiste;
	}

	public function setPilPoints($pilPoints)
	{
		$this->_pilPoints = (int)$pilPoints;
		return $this;
	}
	public function getPilPoints()
	{
		return $this->_pilPoints;
	}

	public function setPilPoids($pilPoids)
	{
		$this->_pilPoids = (float)$pilPoids;
		return $this;
	}
	public function getPilPoids()
	{
		return $this->_pilPoids;
	}

	public function setPilTaille($pilTaille)
	{
		$this->_pilTaille = (float)$pilTaille;
		return $this;
	}
	public function getPilTaille()
	{
		return $this->_pilTaille;
	}

	public function setPilTexte($pilTexte)
	{
		$this->_pilTexte = (string)$pilTexte;
		return $this;
	}
	public function getPilTexte()
	{
		return $this->_pilTexte;
	}

	public function setEcurie($ecurie)
	{
		$this->_ecurie = $ecurie;
		return $this;
	}
	public function getEcurie()
	{
		return $this->_ecurie;
	}
	
	public function setPhotos($photos)
	{
		$this->_photos = $photos;
		return $this;
	}
	public function getPhotos()
	{
		return $this->_photos;
	}
	
	public function setSponsors($sponsors)
	{
		$this->_sponsors = $sponsors;
		return $this;
	}
	public function getSponsors()
	{
		return $this->_sponsors;
	}
	
	public function toArray()
	{
		$tab = array();
		$tab['pilnum']=$this->_pilNum;
		if(!is_null($this->_pays))
		{
			$tab['paynum']=$this->_pays->getPayNum();
		}
		if(!is_null($this->_ecurie))
		{
			$tab['ecunum']=$this->_ecurie->getEcuNum();
		}
		$tab['pilnom']=$this->_pilNom;
		$tab['pilprenom']=$this->_pilPrenom;
		$tab['pildatenais']=date('Y-m-d',strtotime($this->_pilDateNais));
		$tab['pilpigiste']=$this->_pilPigiste;
		$tab['pilpoints']=$this->_pilPoints;
		$tab['pilpoids']=$this->_pilPoids;
		$tab['piltaille']=$this->_pilTaille;
		$tab['piltexte']=$this->_pilTexte;
		
		return $tab;
	}
}